package com.ruoyi.project.jiaqin.companyindustry.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.jiaqin.companyindustry.domain.CompanyIndustry;
import com.ruoyi.project.jiaqin.companyindustry.service.ICompanyIndustryService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 企业行业Controller
 * 
 * @author admin
 * @date 2021-01-26
 */
@Controller
@RequestMapping("/jiaqin/companyindustry")
public class CompanyIndustryController extends BaseController
{
    private String prefix = "jiaqin/companyindustry";

    @Autowired
    private ICompanyIndustryService companyIndustryService;

    @RequiresPermissions("jiaqin:companyindustry:view")
    @GetMapping()
    public String companyindustry()
    {
        return prefix + "/companyindustry";
    }

    /**
     * 查询企业行业列表
     */
    @RequiresPermissions("jiaqin:companyindustry:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CompanyIndustry companyIndustry)
    {
        startPage();
        List<CompanyIndustry> list = companyIndustryService.selectCompanyIndustryList(companyIndustry);
        return getDataTable(list);
    }

    /**
     * 导出企业行业列表
     */
    @RequiresPermissions("jiaqin:companyindustry:export")
    @Log(title = "企业行业", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CompanyIndustry companyIndustry)
    {
        List<CompanyIndustry> list = companyIndustryService.selectCompanyIndustryList(companyIndustry);
        ExcelUtil<CompanyIndustry> util = new ExcelUtil<CompanyIndustry>(CompanyIndustry.class);
        return util.exportExcel(list, "companyindustry");
    }

    /**
     * 新增企业行业
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存企业行业
     */
    @RequiresPermissions("jiaqin:companyindustry:add")
    @Log(title = "企业行业", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CompanyIndustry companyIndustry)
    {
        return toAjax(companyIndustryService.insertCompanyIndustry(companyIndustry));
    }

    /**
     * 修改企业行业
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        CompanyIndustry companyIndustry = companyIndustryService.selectCompanyIndustryById(id);
        mmap.put("companyIndustry", companyIndustry);
        return prefix + "/edit";
    }

    /**
     * 修改保存企业行业
     */
    @RequiresPermissions("jiaqin:companyindustry:edit")
    @Log(title = "企业行业", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CompanyIndustry companyIndustry)
    {
        return toAjax(companyIndustryService.updateCompanyIndustry(companyIndustry));
    }

    /**
     * 删除企业行业
     */
    @RequiresPermissions("jiaqin:companyindustry:remove")
    @Log(title = "企业行业", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(companyIndustryService.deleteCompanyIndustryByIds(ids));
    }
}
